﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsDMDoiTuongTapHopChiPhi
    {
        private string mKhoa = "";
        private string mKhoaLoaiDoiTuongTapHopChiPhi = "";
        private string mMa = "";
        private string mTenViet = "";
        private string mTenAnh = "";
        private string mKhoaDoiTuongTapHopChiPhi = "";
        private string mDienGiai = "";
        private string mKhoaNhanVienCapNhat = "";
        private int mActive = 1;
        
        public void ClearTemp(string pKeyTable)
        {
            string commandText = "DELETE FROM ST_DoiTuongTapHopChiPhiChiTietTmp WHERE Khoa = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
            //commandText = "DELETE FROM ST_DoiTuongTapHopChiPhiChiTietTmp WHERE Khoa = '" + pKeyTable.Trim() + "'";
            //DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }
        public bool DelData(string pKhoa)
        {
            IDataParameter parameter = null;
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "DELETE FROM DM_DoiTuongTapHopChiPhi WHERE Khoa = '" + pKhoa.Trim() + "'";
                bool flag2 = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }) > 0;
                flag = flag2;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }
        public bool DeleteData(string pKhoa)
        {
            bool flag = false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, pKhoa);
                commandParameters[1] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "sp_DM_DTTHCPDel", commandParameters);
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetDetailDichVu(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " Select * From DM_DoiTuongTapHopChiPhiChiTiet Where KhoaDoiTuongTapHopChiPhi = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }
        public DataTable GetList(string strCondition = "")
        {
            string str2 = "";
            DataTable table;
            if (strCondition.Trim() != "")
            {
                str2 = " WHERE " + strCondition;
            }
            try
            {                
                string commandText = "select * From DM_DoiTuongTapHopChiPhi "+str2;
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }
        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM DM_DoiTuongTapHopChiPhi WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.KhoaLoaiDTTHCP = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.Ma = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.TenViet = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.TenAnh = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.KhoaDTTHCP = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.DienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.KhoaNhanVienCapNhat = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mActive = Conversions.ToInteger(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetInt32));
                    
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }
        public bool Save()
        {
            bool flag = false;
            IDataParameter[] commandParameters = new IDataParameter[9];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.String, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@KhoaLoaiDoiTuongTapHopChiPhi", DbType.String, ParameterDirection.Input, this.KhoaLoaiDTTHCP);
                commandParameters[2] = DBHelper.createParameter("@Ma", DbType.String, ParameterDirection.Input, this.Ma);
                commandParameters[3] = DBHelper.createParameter("@TenViet", DbType.String, ParameterDirection.Input, this.TenViet);
                commandParameters[4] = DBHelper.createParameter("@TenAnh", DbType.String, ParameterDirection.Input, this.TenAnh);
                commandParameters[5] = DBHelper.createParameter("@KhoaDoiTuongTapHopChiPhi", DbType.String, ParameterDirection.Input, this.KhoaDTTHCP);
                commandParameters[6] = DBHelper.createParameter("@DienGiai", DbType.String, ParameterDirection.Input, this.DienGiai);
                commandParameters[7] = DBHelper.createParameter("@KhoaNhanVienCapNhat", DbType.String, ParameterDirection.Input, this.KhoaNhanVienCapNhat);
                commandParameters[8] = DBHelper.createParameter("@Active", DbType.Int64, ParameterDirection.Input, this.Active);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "sp_DM_DoiTuongTapHopChiPhi", commandParameters);
                //if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[0x54].Value, 0, false))
                //{
                //    return true;
                //}
                //if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[0x52].Value, 0, false))
                //{
                //    LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m quỹ!", ""));
                //}
                //if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[0x53].Value, 0, false))
                //{
                //    LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m kho!", ""));
                //}
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }
        public void SetBlank()
        {
            this.mKhoa = "";            
            this.mKhoaLoaiDoiTuongTapHopChiPhi = "";
            this.mMa = "";
            this.mTenViet = "";
            this.mTenAnh = "";
            this.mKhoaDoiTuongTapHopChiPhi = "";
            this.mDienGiai = "";
            this.mKhoaNhanVienCapNhat = "";          
        }
        public DataTable ShowList(string strConditions = "")
        {
            DataTable table;
            string commandText = "";
            string str2 = "";
            try
            {
                if (strConditions.Trim() != "")
                {
                    str2 = " AND " + strConditions;
                }
                commandText = " SELECT Khoa, Rtrim(Ma) as Ma, Rtrim(Ten" + modGeneral.H_LANGUAGE + ") as Ten  FROM DM_DoiTuongTapHopChiPhi WHERE Active = 1 " + str2 + " ORDER BY 3 ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }        

        /// <summary>
        /// Created by: Nguyen Thanh Toan 13/12/2011
        /// </summary>
        public string SearchByCode(string strCode = "", string strCondition = "")
        {
            string str4;
            string commandText = "";
            string str3 = "";
            string str = "";
            try
            {
                if (strCode.Trim() != "")
                {
                    str3 = " AND RTRIM(Ma) = '" + strCode.Trim() + "'";
                }
                if (strCondition.Trim() != "")
                {
                    str3 = str3 + " AND " + strCondition;
                }
                commandText = "SELECT Khoa, Ma, Ten" + modGeneral.H_LANGUAGE + " as Ten  FROM DM_DoiTuongTapHopChiPhi WHERE Active = 1 " + str3;
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    str = modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString).ToString() + "|" + modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString).ToString() + "|" + modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString).ToString();
                }
                dataReader.Close();
                str4 = str;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                str4 = "";
                ProjectData.ClearProjectError();
                return str4;
                ProjectData.ClearProjectError();
            }
            return str4;
        }
        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }
        public string KhoaLoaiDTTHCP
        {
            get
            {
                return this.mKhoaLoaiDoiTuongTapHopChiPhi;
            }
            set
            {
                this.mKhoaLoaiDoiTuongTapHopChiPhi = value;
            }
        }
        public string Ma
        {
            get
            {
                return this.mMa;
            }
            set
            {
                this.mMa = value;
            }
        }
        public string TenViet
        {
            get
            {
                return this.mTenViet;
            }
            set
            {
                this.mTenViet = value;
            }
        }
        public string TenAnh
        {
            get
            {
                return this.mTenAnh;
            }
            set
            {
                this.mTenAnh = value;
            }
        }
        public string KhoaDTTHCP
        {
            get
            {
                return this.mKhoaDoiTuongTapHopChiPhi;
            }
            set
            {
                this.mKhoaDoiTuongTapHopChiPhi = value;
            }
        }
        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }
        public string KhoaNhanVienCapNhat
        {
            get
            {
                return this.mKhoaNhanVienCapNhat;
            }
            set
            {
                this.mKhoaNhanVienCapNhat = value;
            }
        }
        public int Active
        {
            get
            {
                return this.mActive;
            }
            set
            {
                this.mActive = value;
            }
        }

    }
}

